import numpy as np
import cv2
import os  #用于地址拼接os.path.join()；获取文件夹目录列表os.dirlist()

# def read_velodyne_bin(bin_path):
#     # 每个点有 (X, Y, Z, intensity) 共 4 个 float32
#     points = np.fromfile(bin_path, dtype=np.float32).reshape(-1, 4)
#     return points
#
# bin_file = 'E:/Environment/KITTI/training/velodyne/000000.bin'
# points = read_velodyne_bin(bin_file)
#
# # 点云总数
# print(f'点云数量: {points.shape[0]}')
# # 打印前5个点的坐标与强度
# print(f'前5个点:\n{points[:5]}')


velodyne_path = "F:\\Environment\\KITTI\\training\\velodyne\\000000.bin"
# 每个点有 (X, Y, Z, intensity) 共 4 个 float32
# points = np.fromfile(velodyne_path, dtype=np.float32).reshape(-1, 4)
# print("点云数量：", points.shape[0])
# print(f"打印点云的坐标与强度:\n {points[0:5,:]}")
"""
打印点云的坐标与强度:
 [[1.8324e+01 4.9000e-02 8.2900e-01 0.0000e+00]
 [1.8344e+01 1.0600e-01 8.2900e-01 0.0000e+00]
 [5.1299e+01 5.0500e-01 1.9440e+00 0.0000e+00]
 [1.8317e+01 2.2100e-01 8.2900e-01 0.0000e+00]
 [1.8352e+01 2.5100e-01 8.3000e-01 9.0000e-02]]
"""
velodyne_path = "F:\\Environment\\KITTI\\training\\velodyne\\000000.bin"
# tt = os.path.splitext(velodyne_path,)    # 使用os.path.splitext()去分割文件路径，提取文件的扩展名部分
# print(tt)
# print(type(tt[1]))
# print(tt[1])
"""
('F:\\Environment\\KITTI\\training\\velodyne\\000000', '.bin')
<class 'str'>
.bin
"""

# def read_points(velodyne_path, dim=4):
#     suffix = os.path.splitext(velodyne_path)[1]     # 使用os.path.splitext()函数分割文件路径，提取文件的扩展名部分
#     assert suffix in ['.bin', '.ply']
#     if suffix == '.bin':
#         return np.fromfile(velodyne_path, dtype=np.float32).reshape(-1, dim)     # 如果后缀名是.bin，则读取点云文件，并转换为np数组，形状为(N,4)
#     else:
#         raise NotImplementedError
# image_path = "F:\\Environment\\KITTI\\training\\image_2\\000000.png"
# image = cv2.imread(image_path)
# print(f"图片形状：{image.shape}")


# image_dir = "F:\\Environment\\KITTI\\training\\image_2"  # 设置文件夹路径
# img_files = os.listdir(image_dir)
# # 批量读取并打印图片信息
# for file in img_files[0:5]:
#     if file.endswith(".png"):
#         img_path = os.path.join(image_dir, file)
#         img = cv2.imread(img_path)
#         if img is None:
#             print(f"无法读取图片: {img_path}")
#             continue
#         print(f"{file} 图片形状: {img.shape}")
"""
000000.png 图片形状: (370, 1224, 3)
000001.png 图片形状: (375, 1242, 3)
000002.png 图片形状: (375, 1242, 3)
000003.png 图片形状: (375, 1242, 3)
000004.png 图片形状: (375, 1242, 3)
"""

# labels_path = "F:\\Environment\\KITTI\\training\\label_2"
# labels = os.listdir(labels_path)
# for label in labels[0:3]:
#     label_path = os.path.join(labels_path,label)
#     with open(label_path,"r") as files:
#         lines = files.readlines()
#         print(f"{label}标签:")
#         for line in lines:
#             print(line.strip())
"""
000000.txt标签:
Pedestrian 0.00 0 -0.20 712.40 143.00 810.73 307.92 1.89 0.48 1.20 1.84 1.47 8.41 0.01
000001.txt标签:
Truck 0.00 0 -1.57 599.41 156.40 629.75 189.25 2.85 2.63 12.34 0.47 1.49 69.44 -1.56
Car 0.00 0 1.85 387.63 181.54 423.81 203.12 1.67 1.87 3.69 -16.53 2.39 58.49 1.57
Cyclist 0.00 3 -1.65 676.60 163.95 688.98 193.93 1.86 0.60 2.02 4.59 1.32 45.84 -1.55
DontCare -1 -1 -10 503.89 169.71 590.61 190.13 -1 -1 -1 -1000 -1000 -1000 -10
DontCare -1 -1 -10 511.35 174.96 527.81 187.45 -1 -1 -1 -1000 -1000 -1000 -10
DontCare -1 -1 -10 532.37 176.35 542.68 185.27 -1 -1 -1 -1000 -1000 -1000 -10
DontCare -1 -1 -10 559.62 175.83 575.40 183.15 -1 -1 -1 -1000 -1000 -1000 -10
000002.txt标签:
Misc 0.00 0 -1.82 804.79 167.34 995.43 327.94 1.63 1.48 2.37 3.23 1.59 8.55 -1.47
Car 0.00 0 -1.67 657.39 190.13 700.07 223.39 1.41 1.58 4.36 3.18 2.27 34.38 -1.58
"""
# calib_path = "F:\\Environment\\KITTI\\training\\calib\\000000.txt"
# with open(calib_path,"r") as f:
#     lines = f.readlines()
# lines = [line.strip() for line in lines]    #列表推导公式[line*2 for line in lines[1:]]
# print(lines)
# for calib in lines:
#     print(calib.strip())
"""
['P0: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 0.000000000000e+00 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00\n', 'P1: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 -3.797842000000e+02 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00\n', 'P2: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 4.575831000000e+01 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 -3.454157000000e-01 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 4.981016000000e-03\n', 'P3: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 -3.341081000000e+02 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 2.330660000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 3.201153000000e-03\n', 'R0_rect: 9.999128000000e-01 1.009263000000e-02 -8.511932000000e-03 -1.012729000000e-02 9.999406000000e-01 -4.037671000000e-03 8.470675000000e-03 4.123522000000e-03 9.999556000000e-01\n', 'Tr_velo_to_cam: 6.927964000000e-03 -9.999722000000e-01 -2.757829000000e-03 -2.457729000000e-02 -1.162982000000e-03 2.749836000000e-03 -9.999955000000e-01 -6.127237000000e-02 9.999753000000e-01 6.931141000000e-03 -1.143899000000e-03 -3.321029000000e-01\n', 'Tr_imu_to_velo: 9.999976000000e-01 7.553071000000e-04 -2.035826000000e-03 -8.086759000000e-01 -7.854027000000e-04 9.998898000000e-01 -1.482298000000e-02 3.195559000000e-01 2.024406000000e-03 1.482454000000e-02 9.998881000000e-01 -7.997231000000e-01\n', '\n'] 

P0: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 0.000000000000e+00 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00
P1: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 -3.797842000000e+02 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00
P2: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 4.575831000000e+01 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 -3.454157000000e-01 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 4.981016000000e-03
P3: 7.070493000000e+02 0.000000000000e+00 6.040814000000e+02 -3.341081000000e+02 0.000000000000e+00 7.070493000000e+02 1.805066000000e+02 2.330660000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 3.201153000000e-03
R0_rect: 9.999128000000e-01 1.009263000000e-02 -8.511932000000e-03 -1.012729000000e-02 9.999406000000e-01 -4.037671000000e-03 8.470675000000e-03 4.123522000000e-03 9.999556000000e-01
Tr_velo_to_cam: 6.927964000000e-03 -9.999722000000e-01 -2.757829000000e-03 -2.457729000000e-02 -1.162982000000e-03 2.749836000000e-03 -9.999955000000e-01 -6.127237000000e-02 9.999753000000e-01 6.931141000000e-03 -1.143899000000e-03 -3.321029000000e-01
Tr_imu_to_velo: 9.999976000000e-01 7.553071000000e-04 -2.035826000000e-03 -8.086759000000e-01 -7.854027000000e-04 9.998898000000e-01 -1.482298000000e-02 3.195559000000e-01 2.024406000000e-03 1.482454000000e-02 9.998881000000e-01 -7.997231000000e-01
"""
# i = "ab cd ef"
# p = i.split(" ")
# print(p)

# p1 = np.array([[1,2,3,4],
#                [4,5,6,7],
#                [8,9,0,1],
#                [2,2,3,6]])
# p2 = np.array([[1],[2],[3],[4]])
# p3 = np.concatenate([p1,p2],axis=1)
# print(p3)

# labels_path = "F:\\Environment\\KITTI\\training\\label_2\\000002.txt"
# with open(labels_path,"r") as f:
#     lines = f.readlines()
# print(lines)
# lines = [line.strip().split(" ") for line in lines]
# print(lines)
# print(np.array([line[3] for line in lines],dtype=np.float32))
"""
['Misc 0.00 0 -1.82 804.79 167.34 995.43 327.94 1.63 1.48 2.37 3.23 1.59 8.55 -1.47\n', 'Car 0.00 0 -1.67 657.39 190.13 700.07 223.39 1.41 1.58 4.36 3.18 2.27 34.38 -1.58\n']
[['Misc', '0.00', '0', '-1.82', '804.79', '167.34', '995.43', '327.94', '1.63', '1.48', '2.37', '3.23', '1.59', '8.55', '-1.47'], 
['Car', '0.00', '0', '-1.67', '657.39', '190.13', '700.07', '223.39', '1.41', '1.58', '4.36', '3.18', '2.27', '34.38', '-1.58']]
 类别   截断比例 遮挡等级 观测角度   ( x1,      y1,       x2,       y2 )    高度(h)  宽度(w)  长度(l)  (x,       y,       z)  物体绕y轴的旋转角度
                                2D边界框,左上角(x1, y1),右下角(x2, y2)    (        3D尺寸       )  物体在相机坐标系下的3D坐标位置
"""


"""
Path to dataset: None
startwhith None
"""
# import argparse
# def main(args):
#     print("Path to dataset:",args.path)
#     print('startwhith',args.prefix)
#
#
# if __name__ == "__main__":
#     parser = argparse.ArgumentParser(description = "This is a test.")     # 创建参数解析器对象parser
#     parser.add_argument('--path',type = str,help = 'Path to dataset.')     # 添加命令行参数
#     parser.add_argument('--prefix',type = str, help = 'startwhith')
#
#     args = parser.parse_args()         # 解析命令行参数
#     main(args)


"""
100%|██████████| 100/100 [00:10<00:00,  9.15it/s]
"""
# from tqdm import tqdm
# import time
#
# ids = range(100)  # 一个有100个元素的列表
# for id in tqdm(ids):
#     # 模拟任务
#     time.sleep(0.1)

height = [40, 20, 80]
occluded = [0, 2, 1]
truncated = [0.0, 0.3, 0.1]

print(zip(height,occluded,truncated))


